package org.apache.lucene.demo;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.IOException;

/*
 * 用户的自定义用于以字符串为源的Reader， 添加了一些方便的方法
 */
public class UserCharArrayReader extends CharArrayReader
{

	public UserCharArrayReader(char[] buf)
	{
		super(buf);
	}
	
	public UserCharArrayReader(char[] buf, int offset, int length)
	{
		super(buf, offset, length);
	}
	
	public String readLine() throws IOException
	{
		//到达文件末尾了！
		if (this.pos == this.count)
		{
			return null;
		}
		else
		{
			String ret = new String("");
			char chr;
			while ((this.pos != this.count) && 
					((chr = (char)(this.read())) != '\n'))
			{
				ret += chr;
			}
			return ret;
		}
	}
}